package com.hl.sfzy.service;

import com.hl.sfzy.entity.LogonUser;
import com.hl.sfzy.mapper.LogonUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: sfzy
 * @description: 孙源源-用户注册
 * @author: Syy
 * @create: 2024-09-07 15:25
 **/
@Service
public class RegisterUserService {
    @Autowired
    private LogonUserMapper logonUserMapper;

    //注册业务1
    public int register(LogonUser logonUser) {
        return logonUserMapper.insertDynamic(logonUser);
    }

    //判断手机号是否已注册业务
    public int selectByPhone(String phone) {
        LogonUser user = logonUserMapper.findLogonUserByPhone(phone);
        if (user == null) {
            return 1;//没找到用户,返回1(可以注册)
        } else if (user.getRole() != 3) {
            return 1;//找到用户了,但是role不是3,返回1(不是用户,可以注册)
        } else return -1;//找到用户了,role也是3返回-1(是用户,已被注册,不能注册)
    }

    //注册业务2
    public int register2(String phone, String username, String password) {
        return logonUserMapper.updateByPhoneDynamic(phone, username, password);
    }

    //判断用户名是否已注册业务
    public int selectByUsername(String username) {
        LogonUser user = logonUserMapper.findLogonUserByUsername(username);
        if (user == null) {
            return 1;//没找到用户,返回1(可以注册)
        } else if (user.getRole() != 3) {
            return 1;//找到用户了,但是role不是3,返回1(不是用户,可以注册)
        } else return -1;//找到用户了,role也是3返回-1(是用户,已被注册,不能注册)
    }
}
